package com.sangfor.ssl.service.timeqry;

import kotlin.UByte;

/* loaded from: classes2.dex */
public final class FormatTransfer {
    public static byte[] toHH(int i) {
        return new byte[]{(byte) ((i >> 24) & 255), (byte) ((i >> 16) & 255), (byte) ((i >> 8) & 255), (byte) (i & 255)};
    }

    public static byte[] toHH(short s) {
        return new byte[]{(byte) ((s >> 8) & 255), (byte) (s & 255)};
    }

    public static byte[] toLH(int i) {
        return new byte[]{(byte) (i & 255), (byte) ((i >> 8) & 255), (byte) ((i >> 16) & 255), (byte) ((i >> 24) & 255)};
    }

    public static byte[] toLH(short s) {
        return new byte[]{(byte) (s & 255), (byte) ((s >> 8) & 255)};
    }

    public static int hBytesToInt(byte[] bArr) {
        byte b;
        byte b2;
        int i = 0;
        for (int i2 = 0; i2 < 3; i2++) {
            if (bArr[i2] >= 0) {
                b2 = bArr[i2];
            } else {
                i += 256;
                b2 = bArr[i2];
            }
            i = (i + b2) * 256;
        }
        if (bArr[3] >= 0) {
            b = bArr[3];
        } else {
            i += 256;
            b = bArr[3];
        }
        return i + b;
    }

    public static int lBytesToInt(byte[] bArr) {
        byte b;
        byte b2;
        int i = 0;
        for (int i2 = 0; i2 < 3; i2++) {
            int i3 = 3 - i2;
            if (bArr[i3] >= 0) {
                b2 = bArr[i3];
            } else {
                i += 256;
                b2 = bArr[i3];
            }
            i = (i + b2) * 256;
        }
        if (bArr[0] >= 0) {
            b = bArr[0];
        } else {
            i += 256;
            b = bArr[0];
        }
        return i + b;
    }

    public static long hBytesToLong(byte[] bArr) {
        byte b;
        byte b2;
        long j = 0;
        for (int i = 0; i < 7; i++) {
            if (bArr[i] >= 0) {
                b2 = bArr[i];
            } else {
                j += 256;
                b2 = bArr[i];
            }
            j = (j + b2) * 256;
        }
        if (bArr[7] >= 0) {
            b = bArr[7];
        } else {
            j += 256;
            b = bArr[7];
        }
        return j + b;
    }

    public static long lBytesToLong(byte[] bArr) {
        byte b;
        byte b2;
        long j = 0;
        for (int i = 0; i < 7; i++) {
            int i2 = 7 - i;
            if (bArr[i2] >= 0) {
                b2 = bArr[i2];
            } else {
                j += 256;
                b2 = bArr[i2];
            }
            j = (j + b2) * 256;
        }
        if (bArr[0] >= 0) {
            b = bArr[0];
        } else {
            j += 256;
            b = bArr[0];
        }
        return j + b;
    }

    public static short hBytesToShort(byte[] bArr) {
        int i;
        byte b;
        if (bArr[0] >= 0) {
            i = bArr[0] + 0;
        } else {
            i = 256 + bArr[0];
        }
        int i2 = i * 256;
        if (bArr[1] >= 0) {
            b = bArr[1];
        } else {
            i2 += 256;
            b = bArr[1];
        }
        return (short) (i2 + b);
    }

    public static short lBytesToShort(byte[] bArr) {
        int i;
        byte b;
        if (bArr[1] >= 0) {
            i = bArr[1] + 0;
        } else {
            i = bArr[1] + UByte.MIN_VALUE;
        }
        int i2 = i * 256;
        if (bArr[0] >= 0) {
            b = bArr[0];
        } else {
            i2 += 256;
            b = bArr[0];
        }
        return (short) (i2 + b);
    }

    public static int hBytesToInt(byte[] bArr, int i, int i2) {
        byte[] bArr2 = new byte[i2];
        System.arraycopy(bArr, i, bArr2, 0, i2);
        return hBytesToInt(bArr2);
    }

    public static int lBytesToInt(byte[] bArr, int i, int i2) {
        byte[] bArr2 = new byte[i2];
        System.arraycopy(bArr, i, bArr2, 0, i2);
        return lBytesToInt(bArr2);
    }

    public static short hBytesToShort(byte[] bArr, int i, int i2) {
        byte[] bArr2 = new byte[i2];
        System.arraycopy(bArr, i, bArr2, 0, i2);
        return hBytesToShort(bArr2);
    }

    public static short lBytesToShort(byte[] bArr, int i, int i2) {
        byte[] bArr2 = new byte[i2];
        System.arraycopy(bArr, i, bArr2, 0, i2);
        return lBytesToShort(bArr2);
    }

    public static long lBytesToLong(byte[] bArr, int i, int i2) {
        byte[] bArr2 = new byte[8];
        System.arraycopy(bArr, i, bArr2, 0, i2);
        return lBytesToLong(bArr2);
    }

    public static long hBytesToLong(byte[] bArr, int i, int i2) {
        byte[] bArr2 = new byte[8];
        System.arraycopy(bArr, i, bArr2, 0, i2);
        return hBytesToLong(bArr2);
    }
}
